﻿# coding: utf-8

from django.db import models
from django.contrib.auth.models import User


PRIORIDADE_CHOICES = tuple([(i, i) for i in range(1, 6)])

RESOLUCAO_CHOICES = (
    ('A', 'Aberta'),
    ('F', 'Fechada'),
)

class Status(models.Model):
    class Meta:
        verbose_name = u'status'
        verbose_name_plural = u'status'

    nome = models.CharField(max_length=30, unique=True)
    resolucao = models.CharField(max_length=1, choices=RESOLUCAO_CHOICES, default=RESOLUCAO_CHOICES[0])

    def __unicode__(self):
        return self.nome

class Severidade(models.Model):
    class Meta:
        verbose_name = u'severidade'
        verbose_name_plural = u'severidades'

    nome = models.CharField(max_length=30, unique=True)

    def __unicode__(self):
        return self.nome

class StatusTransicoes(models.Model):
    class Meta:
        verbose_name = u'transição'
        verbose_name_plural = u'transições'
        ordering = ['status_de', 'status_para']

    nome = models.CharField(max_length=30)
    status_de = models.ForeignKey(Status, related_name='origens')
    status_para = models.ForeignKey(Status, related_name='destinos')

    def __unicode__(self):
        return '%s (%s -> %s)' % (self.nome, self.status_de, self.status_para)

class Bug(models.Model):
    class Meta:
        verbose_name = u'bug'
        verbose_name_plural = u'bugs'

    titulo = models.CharField(max_length=150)
    resumo = models.TextField()
    status = models.ForeignKey(Status)
    prioridade = models.IntegerField(choices=PRIORIDADE_CHOICES)
    severidade = models.ForeignKey(Severidade)
    descricao = models.TextField()
    passos_para_reproduzir = models.TextField()
    url = models.URLField()
    reportado_por = models.ForeignKey(User, related_name='reportador')
    atribuido_para = models.ForeignKey(User, verbose_name=u'atribuído para', related_name='solucionador')
    solucao = models.TextField(u'solução')
    prazo_estimado = models.DateTimeField()
    prazo_atual = models.DateTimeField()


    def __unicode__(self):
        return self.titulo
